package com.example.my.agiftthat.ui.list;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.my.agiftthat.R;
import com.example.my.agiftthat.config.Url;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by My on 2016/12/3.
 */

public class FragmentList extends Fragment {
    private Context mContext = null;
    private TabLayout tabLayout_list;
    private ViewPager viewPager_list;
    private List<Fragment> mList = new ArrayList<>();
    private String[] mArrListTitles = null;
    private String[] url = {Url.LIST_TJ,Url.LIST_TOP,Url.LIST_YC,Url.LIST_XX,};
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=getActivity();
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.framgent_list,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout_list = (TabLayout) view.findViewById(R.id.tabLayout_list);
        viewPager_list = (ViewPager) view.findViewById(R.id.viewPager_list);
    }



    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mArrListTitles = getResources().getStringArray(R.array.mArrListTitles);
        for (int i = 0; i < mArrListTitles.length; i++) {
            CommentFragment fragment=new CommentFragment();
            Bundle bundle = new Bundle();
            bundle.putString("index",url[i]);
            fragment.setArguments(bundle);
            mList.add(fragment);
        }
        TabListAdapter adapter = new TabListAdapter(getChildFragmentManager(), mList, mArrListTitles);
        viewPager_list.setAdapter(adapter);
        tabLayout_list.setupWithViewPager(viewPager_list);
    }
}
